def prost(x):
    for i in range(2,x):
        if x % i ==0:
            return 0
    return 1

print('введите 4-х значное натуральное число ')

x = int(input())
kol = 0
MP = 0
if x >= 1000 and x < 10000 and x > 0:        
    x = str(x)
  
    s = x[0]
    if prost(int(s)) ==1:
        kol += 1
        MP = max(int(s),MP)
        
    s = x[1]
    if prost(int(s)) ==1:
        kol +=1
        MP = max(int(s),MP)
        
    s = x[2]
    if prost(int(s)) ==1:
        kol +=1
        MP = max(int(s),MP)
        
    s = x[3]
    if prost(int(s)) ==1:
        kol +=1
        MP = max(int(s),MP)
        
    s = x[:2]
    if prost(int(s)) ==1:
        kol +=1
        MP = max(int(s),MP)
    
    s = x[:3]
    if prost(int(s)) ==1:
        kol +=1
        MP = max(int(s),MP)

    s = x
    if prost(int(s)) ==1:
        kol +=1
        MP = max(int(s),MP)

    s = x[2] +x[3]
    if prost(int(s)) ==1:
        kol +=1
        MP = max(int(s),MP)
    
    s =x[1] +x[2] +x[3] 
    if prost(int(s)) ==1:
        kol +=1
        MP = max(int(s),MP)
        
    if kol > 0:
        print(MP)
    else:
        print(0)
else:
    print('введённое число - не соответствует требованиям')
